#include"stc.h"

int main()
{
	int Month;
	int Y; 	
	int y = 1; 
	int day = 1;
	int Firstday; 
	int k = 0;
	int i = 0;
	int m = 0;
	int tday;
	int dmonth;
R:
	PutStr("Input Year(1-9999999) : ");
	Y = GetInt();
	PutStr("\nInput Month(1-12) : ");
	Month = GetInt();		
	if(Month < 0 || Month > 12 || Y < 1 || Y > 10000) goto R;
	dmonth = 30 * (Month == 4 || Month == 6 || Month == 9 || Month == 11)
		+ 31 * (Month == 1 || Month == 3 || Month == 5 || Month == 7 || Month == 8 || Month == 10 || Month == 12) 		
		+ (28 + (Y % 400 == 0 || (Y % 4 == 0 && Y % 100 != 0))) * (Month == 2);
R1:
	y = y + 1;
	if(y >= Y) goto L1;
	k = k + (y % 400 == 0 || y % 4 == 0 && y % 100 != 0);
	goto R1;
L1: 
	tday = k * 366 + (Y - k - 1) * 365;
	y = 0;
L2: 
	m = m + 1;
	if(m >= Month) goto E;
	tday = tday 
		+ 30 * (m == 4 || m == 6 || m == 9 || m == 11)
		+ 31 * (m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12)		
		+ (28 + (Y % 400 == 0 || (Y % 4 == 0 && Y % 100 != 0))) * (m == 2);
	goto L2;
E:
	Firstday = (1 + (tday % 7)) % 7; 
	y = Firstday;
	PutStr("\nSu  Mo  Tu  We  Th  Fr  Sa\n");
	PutStr("----------------------------\n");	
L4: 
	if(i >= Firstday) goto E2;
	PutStr("    ");
	i = i + 1;
	goto L4;
E2:
	day = day + 1;
	if(day > dmonth) goto E3;
	if(day>9) goto L3;
	PutStr(" ");
L3:
	PutInt(day);
	PutStr("  ");
	y = y + 1;
	if(y < 7)  goto E2;
	PutStr("\n");
	y = 0;
	goto E2;
E3:
	PutStr("\n");
}


